package com.example.myapplication;

import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

public class RateManager {

    private DatabaseHelper dbHelper;

    public RateManager(DatabaseHelper dbHelper) {
        this.dbHelper = dbHelper;
    }

    public void updateExchangeRates() {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        // 创建新的 ExchangeRate 对象列表
        List<ExchangeRate> newRates = new ArrayList<>();

        // 假设你从网络获取了汇率数据，使用当前时间戳作为 timestamp
        String timestamp = "2023-05-19";  // 使用实际的时间戳

        // 添加汇率数据
        newRates.add(new ExchangeRate("USD", "6.45", timestamp));
        newRates.add(new ExchangeRate("EUR", "7.85", timestamp));
        newRates.add(new ExchangeRate("GBP", "8.20", timestamp));
        newRates.add(new ExchangeRate("AUD", "4.15", timestamp));

        // 清空旧的数据
        dbHelper.deleteAllRates(db);

        // 将新数据插入到数据库
        dbHelper.addExchangeRates(db, newRates);
    }
}
